package com.xyulu.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author luming
 * @version 1.0
 * @date
 */
@RestController
public class DemoController {


    @GetMapping("/break/{id}")
//    @HystrixCommand(fallbackMethod = "fallbackMethod")  //指定方法进行熔断
    @HystrixCommand(defaultFallback = "fallbackMethod")
    public String testBreak(@PathVariable("id") Integer id) {
        if (id < 0) {
            throw new RuntimeException("数据不合法!!!");
        }
        return "demo is ok";
    }


    public String fallbackMethod(Integer id) {
        return "该服务已被熔断，当前数据不合法: " + id;
    }

    public String fallbackMethod() {
        return "服务不可用";
    }

}
